<template>
  <van-nav-bar
      left-arrow
      title="验证消息"
      @click-left="onClickLeft"
  />
  <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
          v-model="form.verifyMessage"
          name="verifyMessage"
          label="验证消息"
          placeholder="验证消息，告诉Ta你是谁"
      />
      <van-field name="topStatus" label="是否置顶">
        <template #input>
          <van-switch v-model="form.topStatus" size="20" />
        </template>
      </van-field>
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        确定
      </van-button>
    </div>
  </van-form>
</template>

<script>
import {addToFriend} from "@/api/friend";
import {Toast} from "vant";
import {router} from "@/router";

export default {
  name: "verify",
  data(){
    return{
      form: {
        verifyMessage: '',
        topStatus: false,
        userId: 0,
        friendUserId: 0
      },
    }
  },
  methods: {
    onClickLeft() {
      history.back()
    },
    onSubmit() {
      Toast.loading({
        message: '提交中...',
        forbidClick: true,
      });
      addToFriend(this.form).then(response => {
        if (response.code === 200) {
          Toast.success(response.message)
          router.replace({path: '/home'})
        }
      })
    }
  },
  created() {
    this.form.userId = JSON.parse(sessionStorage.getItem("user")).userId
    this.form.friendUserId = router.currentRoute.value.params.friendUserId
  }
}
</script>

<style scoped>
.van-nav-bar {
  --van-nav-bar-background-color: rgb(0, 174, 239);
  --van-nav-bar-icon-color: rgb(0, 0, 0);
  --van-nav-bar-title-text-color: rgb(255, 255, 255);
  --van-nav-bar-height: 75px;
}
</style>